package cards;

import model.Board;
import model.Player;
import fields.Shipping;

public class GoToShipping extends GoTo {

	public GoToShipping(String text) {
		super(text);
	}

	@Override
	public void execute(Player player) {
		// - 1 to change his position to an index and + 1 to start with considering the next field.
		for(int i = player.getPosition() - 1 + 1; /*Never stop*/ ; i++){ 
			if(Board.fields[i % 40] instanceof Shipping){
				Shipping s = (Shipping)Board.fields[i % 40];
				int rent = s.getOwner() == null ? 0 : s.getRent();
				player.setPosition(s.getNumber());
				s.landOnField(player, rent * 2);
				//Rent times 2 is special rate for chance card
				return;
			}
		}
	}
	
	@SuppressWarnings("unused") // this is a test.
	public static void main(String[] args) {
		new Board();
		Player me = new Player("Ronnie", 2, 30000);
		System.out.println(me);
		Player looser = new Player("Looser", 1, 10000);
		System.out.println(looser);
		
		String text = 
				"Ryk brikken frem til det nærmeste rederi og " +
				"betal ejeren to gange den leje, han ellers er " +
				"berettiget til. Hvis selskabet ikke ejes af " +
				"nogen kan De købe det af banken.";
		Card card = new GoToShipping(text);
		card.execute(me);
		
		System.out.println(me);
		
		card.execute(looser);
		System.out.println(looser);
		System.out.println(me);
		
	}
}











